package _09练习;

import java.awt.EventQueue;

import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JTextField;
import javax.swing.JButton;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;

public class BMI extends JFrame {

	private JPanel contentPane;
	private JTextField textField;
	private JTextField textField_1;

	/**
	 * Launch the application.
	 */
	public static void main(String[] args) {
		EventQueue.invokeLater(new Runnable() {
			public void run() {
				try {
					BMI frame = new BMI();
					frame.setVisible(true);
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		});
	}

	/**
	 * Create the frame.
	 */
	public BMI() {
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		setBounds(100, 100, 562, 417);
		contentPane = new JPanel();
		contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));

		setContentPane(contentPane);
		contentPane.setLayout(null);
		
		JLabel lblNewLabel = new JLabel("体重指数计算");
		lblNewLabel.setBounds(237, 10, 78, 26);
		contentPane.add(lblNewLabel);
		
		JLabel weight = new JLabel("体重(kg)");
		weight.setBounds(22, 55, 58, 15);
		contentPane.add(weight);
		
		textField = new JTextField();
		textField.setBounds(75, 52, 66, 21);
		contentPane.add(textField);
		textField.setColumns(10);
		
		JLabel height = new JLabel("身高(m)");
		height.setBounds(164, 55, 58, 15);
		contentPane.add(height);
		
		textField_1 = new JTextField();
		textField_1.setBounds(227, 52, 66, 21);
		contentPane.add(textField_1);
		textField_1.setColumns(10);
		
		
		
		JLabel result = new JLabel("");
		result.setBounds(430, 55, 58, 15);
		contentPane.add(result);
		
		
		
		JButton btnNewButton = new JButton("测一下");
			
		btnNewButton.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				
				double weight = Double.parseDouble(textField.getText());
				double height=Double.parseDouble(textField_1.getText());
				double bmi=weight/(height*height);	
				
				if(bmi<18.5)
				{
					JOptionPane.showMessageDialog(null,"偏瘦");
				}
				else if(bmi>=18.5 && bmi<24.9)
					JOptionPane.showMessageDialog(null,"正常");
				else if(bmi>=25.0 && bmi<29.9)
					JOptionPane.showMessageDialog(null,"偏胖");
				else if(bmi>=30.0 && bmi<34.9)
					JOptionPane.showMessageDialog(null,"肥胖");
				else if(bmi>=35.0 && bmi<39.9)
					JOptionPane.showMessageDialog(null,"重度肥胖");
				else if(bmi>=40.0)
					JOptionPane.showMessageDialog(null,"极重度肥胖");		
			
				
				
				//result.setText(""+result);
			}
		});
		
		btnNewButton.setBounds(303, 51, 97, 23);
		contentPane.add(btnNewButton);
		
	}
}

